package com.naiterui.ehp.bs.wechat.param.custom;

import org.apache.commons.lang3.StringUtils;

import com.naiterui.ehp.bs.wechat.constants.WeChatConstant;
import com.naiterui.ehp.bs.wechat.protocol.msg.custom.CustomImage;
import com.naiterui.ehp.bs.wechat.protocol.msg.custom.CustomMsg;

import lombok.Data;

/**
 * 图片消息
 * @author zhoupeipei
 * @date 2019-07-05 14:58
 * @since 1.0.0
 */
@Data
public class ImageMsgParam extends BaseCustomParam {
    private static final long serialVersionUID = 3728407292866653404L;
    /**
     * 多媒体文件在微信服务器上的id</p>
     * <p>【临时素材】通过IMediaApiService.uploadTempMedia上传获得</p>
     * <p>【永久素材】通过IMediaApiService.uploadMedia上传所得</p>
     */
    private String mediaId;

    /**
     * 参数构造器
     *
     * @param openId  用户openId
     * @param mediaId 图片文件在微信服务器上的id
     *              <p>【临时素材】通过IMediaApiService.uploadTempMedia上传获得</p>
     *              <p>【永久素材】通过IMediaApiService.uploadMedia上传所得</p>
     */
    public ImageMsgParam(String openId, String mediaId) {
        super.setOpenId(openId);
        super.setMsgType(WeChatConstant.KefuMsgType.IMAGE);
        this.mediaId = mediaId;
    }
    @Override
    public CustomMsg getCustomProtocol() {
        if (super.validate() && StringUtils.isNotBlank(mediaId)) {
            CustomImage customImage = new CustomImage(mediaId);
            return new CustomMsg(getOpenId(), customImage, getMsgType());
        }
        return null;
    }
}
